import {
  Count,
  CountSchema,
  Filter,
  repository,
  Where,
} from '@loopback/repository';
import {
  post,
  param,
  get,
  getFilterSchemaFor,
  getWhereSchemaFor,
  patch,
  put,
  del,
  requestBody,
} from '@loopback/rest';
import { Praise } from '../models';
import { PraiseRepository } from '../repositories';

export class PraiseController {
  constructor(
    @repository(PraiseRepository)
    public praiseRepository: PraiseRepository,
  ) { }

  @post('/praises', {
    responses: {
      '200': {
        description: 'Praise model instance',
        content: { 'application/json': { schema: { 'x-ts-type': Praise } } },
      },
    },
  })
  async create(@requestBody() praise: Praise): Promise<Praise> {
    return await this.praiseRepository.create(praise);
  }

  @get('/praises/count', {
    responses: {
      '200': {
        description: 'Praise model count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async count(
    @param.query.object('where', getWhereSchemaFor(Praise)) where?: Where,
  ): Promise<Count> {
    return await this.praiseRepository.count(where);
  }

  @get('/praises', {
    responses: {
      '200': {
        description: 'Array of Praise model instances',
        content: {
          'application/json': {
            schema: { type: 'array', items: { 'x-ts-type': Praise } },
          },
        },
      },
    },
  })
  async find(
    @param.query.object('filter', getFilterSchemaFor(Praise)) filter?: Filter,
  ): Promise<Praise[]> {
    return await this.praiseRepository.find(filter);
  }

  @patch('/praises', {
    responses: {
      '200': {
        description: 'Praise PATCH success count',
        content: { 'application/json': { schema: CountSchema } },
      },
    },
  })
  async updateAll(
    @requestBody() praise: Praise,
    @param.query.object('where', getWhereSchemaFor(Praise)) where?: Where,
  ): Promise<Count> {
    return await this.praiseRepository.updateAll(praise, where);
  }

  @get('/praises/{id}', {
    responses: {
      '200': {
        description: 'Praise model instance',
        content: { 'application/json': { schema: { 'x-ts-type': Praise } } },
      },
    },
  })
  async findById(@param.path.number('id') id: number): Promise<Praise> {
    return await this.praiseRepository.findById(id);
  }

  @patch('/praises/{id}', {
    responses: {
      '204': {
        description: 'Praise PATCH success',
      },
    },
  })
  async updateById(
    @param.path.number('id') id: number,
    @requestBody() praise: Praise,
  ): Promise<void> {
    await this.praiseRepository.updateById(id, praise);
  }

  @put('/praises/{id}', {
    responses: {
      '204': {
        description: 'Praise PUT success',
      },
    },
  })
  async replaceById(
    @param.path.number('id') id: number,
    @requestBody() praise: Praise,
  ): Promise<void> {
    await this.praiseRepository.replaceById(id, praise);
  }

  @del('/praises/{id}', {
    responses: {
      '204': {
        description: 'Praise DELETE success',
      },
    },
  })
  async deleteById(@param.path.number('id') id: number): Promise<void> {
    await this.praiseRepository.deleteById(id);
  }
}
